# coding:utf-8

import unittest
from functools import partial
from functools import update_wrapper

from utils.testcaseutils import TestcaseUtils


def wrapped_partial(func, *args, **kwargs):
    partial_func = partial(func, *args, **kwargs)
    update_wrapper(partial_func, func)
    return partial_func


def testcase_generator(file_name):

    generator = TestcaseUtils()
    cases = generator.read_case_suite(file_name)

    case_suites = []
    for case in cases:
        test_case_name = "TestCase_{test_suite}_{case_name}".format(test_suite=case["test_suite"],
                                                                    case_name=case["case_name"])
        #test_method = partial(generator.test_case, case)
        test_method = wrapped_partial(generator.test_case, case)
        case_suites.append(type(test_case_name, (unittest.TestCase, ), dict(test_request=test_method)))

    return case_suites
